package com.hspedu.threaduse;

/**
 * @author LiuJinTao
 * @className Thread03
 * @date 2024/06/23 15:30
 * @description mian 线程启动两个子线程
 */
public class Thread03 {
    public static void main(String[] args) {
        Thread thread = new Thread(new T1());
        Thread thread1 = new Thread(new T2());
        thread.start();
        thread1.start();
    }
}

// 每隔一秒输出 Hi，输出10次结束
class T2 implements Runnable {
    int count = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println("Hi! " + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (count == 5) break;
        }
    }
}

// 每隔一秒输出 HelloWord，输出10次结束
class T1 implements Runnable {
int count = 0;

    @Override
    public void run() {
        while (true) {
            System.out.println("Hello Word! " + Thread.currentThread().getName());
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if (count == 10) break;
        }
    }
}